<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>oscbnk</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="opcode.html" title="opcode" />
    <link rel="next" href="oscil1.html" title="oscil1" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">oscbnk</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="opcode.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="oscil1.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="oscbnk"></a>
      <div class="titlepage"></div>
      <a id="IndexOscbnk" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">oscbnk</span>
        </h2>
        <p>oscbnk — 
      Mixes the output of any number of oscillators.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp128932320"></a>
        <h2>Description</h2>
        <p>
      This unit generator mixes the output of any number of oscillators. The frequency, phase, and amplitude of each oscillator can be modulated by two LFOs (all oscillators have a separate set of LFOs, with different phase and frequency); additionally, the output of each oscillator can be filtered through an optional parametric equalizer (also controlled by the LFOs).  This opcode is most useful for rendering ensemble (strings, choir, etc.) instruments.
    </p>
        <p>
      Although the LFOs run at k-rate, amplitude, phase and filter modulation are interpolated internally, so it is possible (and recommended in most cases) to use this unit at low (˜1000 Hz) control rates without audible quality degradation.
    </p>
        <p>
      The start phase and frequency of all oscillators and LFOs can be set by a built-in seedable 31-bit random number generator, or specified manually in a function table (GEN2).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp128936240"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>oscbnk</strong></span>  kcps, kamd, kfmd, kpmd, iovrlap, iseed, kl1minf, kl1maxf, \
      kl2minf, kl2maxf, ilfomode, keqminf, keqmaxf, keqminl, keqmaxl, \
      keqminq, keqmaxq, ieqmode, kfn [, il1fn] [, il2fn] [, ieqffn]   \
      [, ieqlfn] [, ieqqfn] [, itabl] [, ioutfn]</pre>
      </div>
      <div class="refsect1">
        <a id="idp128938592"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iovrlap</em></span> -- Number of oscillator units.
    </p>
        <p>
      <span class="emphasis"><em>iseed</em></span> -- Seed value for random number generator (positive integer in the range 1 to 2147483646 (2 ^ 31 - 2)). <span class="emphasis"><em>iseed</em></span> &lt;= 0 seeds from the current time.
    </p>
        <p>
      <span class="emphasis"><em>ieqmode</em></span> -- Parametric equalizer mode
        </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>-1: disable EQ (faster)</p>
            </li>
            <li class="listitem">
              <p>0: peak</p>
            </li>
            <li class="listitem">
              <p>1: low shelf</p>
            </li>
            <li class="listitem">
              <p>2: high shelf</p>
            </li>
            <li class="listitem">
              <p>3: peak (filter interpolation disabled)</p>
            </li>
            <li class="listitem">
              <p>4: low shelf (interpolation disabled)</p>
            </li>
            <li class="listitem">
              <p>5: high shelf (interpolation disabled)</p>
            </li>
          </ul>
        </div>
        <p>

      The non-interpolated modes are faster, and in some cases (e.g. high shelf filter at low cutoff frequencies) also more stable; however, interpolation is useful for avoiding <span class="quote">“<span class="quote">zipper noise</span>”</span> at low control rates.
    </p>
        <p>
      <span class="emphasis"><em>ilfomode</em></span> -- LFO modulation mode, sum of:
        </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>128: LFO1 to frequency</p>
            </li>
            <li class="listitem">
              <p>64: LFO1 to amplitude</p>
            </li>
            <li class="listitem">
              <p>32: LFO1 to phase</p>
            </li>
            <li class="listitem">
              <p>16: LFO1 to EQ</p>
            </li>
            <li class="listitem">
              <p>8: LFO2 to frequency</p>
            </li>
            <li class="listitem">
              <p>4: LFO2 to amplitude</p>
            </li>
            <li class="listitem">
              <p>2: LFO2 to phase</p>
            </li>
            <li class="listitem">
              <p>1: LFO2 to EQ</p>
            </li>
          </ul>
        </div>
        <p>

      If an LFO does not modulate anything, it is not calculated, and the ftable number (<span class="emphasis"><em>il1fn</em></span> or <span class="emphasis"><em>il2fn</em></span>) can be omitted.
    </p>
        <p>
      <span class="emphasis"><em>il1fn</em></span> (optional: default=0) -- LFO1 function table number. The waveform in this table has to be normalized (absolute value &lt;= 1), and is read with linear interpolation.
    </p>
        <p>
      <span class="emphasis"><em>il2fn</em></span> (optional: default=0) -- LFO2 function table number. The waveform in this table has to be normalized, and is read with linear interpolation.
    </p>
        <p>
      <span class="emphasis"><em>ieqffn, ieqlfn, ieqqfn</em></span> (optional: default=0) -- Lookup tables for EQ frequency, level, and Q (optional if EQ is disabled). Table read position is 0 if the modulator signal is less than, or equal to -1, (table length / 2) if the modulator signal is zero, and the guard point if the modulator signal is greater than, or equal to 1. These tables have to be normalized to the range 0 - 1, and have an extended guard point (table length = power of two + 1). All tables are read with linear interpolation.
    </p>
        <p>
      <span class="emphasis"><em>itabl</em></span> (optional: default=0) -- Function table storing phase and frequency values for all oscillators (optional). The values in this table are in the following order (5 for each oscillator unit):

      </p>
        <div class="informalexample">
          <div class="literallayout">
            <p>oscillator phase, lfo1 phase, lfo1 frequency, lfo2 phase, lfo2 frequency, ...</p>
          </div>
        </div>
        <p>

      All values are in the range 0 to 1; if the specified number is greater than 1, it is wrapped (phase) or limited (frequency) to the allowed range. A negative value (or end of table) will use the output of the random number generator.  The random seed is always updated (even if no random number was used), so switching one value between random and fixed will not change others.
    </p>
        <p>
      <span class="emphasis"><em>ioutfn</em></span> (optional: default=0) -- Function table to write phase and frequency values (optional). The format is the same as in the case of <span class="emphasis"><em>itabl</em></span>. This table is useful when experimenting with random numbers to record the best values.
    </p>
        <p>
      The two optional tables (<span class="emphasis"><em>itabl</em></span> and <span class="emphasis"><em>ioutfn</em></span>) are accessed only at i-time. This is useful to know, as the tables can be safely overwritten after opcode initialization, which allows precalculating parameters at i-time and storing in a temporary table before <span class="emphasis"><em>oscbnk</em></span> initialization.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp128965456"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ares</em></span> -- Output signal.
    </p>
        <p>
      <span class="emphasis"><em>kcps</em></span> -- Oscillator frequency in Hz.
    </p>
        <p>
      <span class="emphasis"><em>kamd</em></span> -- AM depth (0 - 1). 

      </p>
        <div class="literallayout">
          <p><br />
(AM output) = (AM input) * ((1 - (AM depth)) + (AM depth) * (modulator))<br />
      </p>
        </div>
        <p>

      If <span class="emphasis"><em>ilfomode</em></span> isn't set to modulate the amplitude, then (AM output) = (AM input) regardless of the value of <span class="emphasis"><em>kamd</em></span>. That means that <span class="emphasis"><em>kamd</em></span> will have no effect.
    </p>
        <p>
      Note: Amplitude modulation is applied before the parametric equalizer. 
    </p>
        <p>
      <span class="emphasis"><em>kfmd</em></span> -- FM depth (in Hz).
    </p>
        <p>
      <span class="emphasis"><em>kpmd</em></span> -- Phase modulation depth.
    </p>
        <p>
      <span class="emphasis"><em>kl1minf, kl1maxf</em></span> -- LFO1 minimum and maximum frequency in Hz.
    </p>
        <p>
      <span class="emphasis"><em>kl2minf, kl2maxf</em></span> --  LFO2 minimum and maximum frequency in Hz. (Note: oscillator and LFO frequencies are allowed to be zero or negative.)
    </p>
        <p>
      <span class="emphasis"><em>keqminf, keqmaxf</em></span> -- Parametric equalizer minimum and maximum frequency in Hz.
    </p>
        <p>
      <span class="emphasis"><em>keqminl, keqmaxl</em></span> -- Parametric equalizer minimum and maximum level.
    </p>
        <p>
      <span class="emphasis"><em>keqminq, keqmaxq</em></span> -- Parametric equalizer minimum and maximum Q.
    </p>
        <p>
      <span class="emphasis"><em>kfn</em></span> -- Oscillator waveform table. Table number can be changed at k-rate (this is useful to select from a set of band-limited tables generated by GEN30, to avoid aliasing). The table is read with linear interpolation.
    </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note: Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        <span class="emphasis"><em>oscbnk</em></span> uses the same random number generator as <span class="emphasis"><em>rnd31</em></span>. So reading <a class="link" href="rnd31.html" title="rnd31"><em class="citetitle">its documentation</em></a> is also recommended.
      </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp128983328"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of oscbnk opcode. It uses the file <a class="ulink" href="examples/oscbnk.csd" target="_top"><em class="citetitle">oscbnk.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp128985104"></a>
          <p class="title">
            <strong>Example 558. Example of the oscbnk opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o oscbnk.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="op">/</span><span class="op">*</span> Written by Istvan Varga <span class="op">*</span><span class="op">/</span>
<span class="ohdr">sr</span>	<span class="op">=</span>  48000
<span class="ohdr">kr</span>	<span class="op">=</span>  750
<span class="ohdr">ksmps</span>	<span class="op">=</span>  64
<span class="ohdr">nchnls</span>	<span class="op">=</span>  2

ga01	<span class="opc">init</span> 0
ga02	<span class="opc">init</span> 0

<span class="op">/</span><span class="op">*</span> sawtooth wave <span class="op">*</span><span class="op">/</span>
i_	<span class="ohdr">ftgen</span> 1, 0, 16384, 7, 1, 16384, <span class="op">-</span>1
<span class="op">/</span><span class="op">*</span> FM waveform <span class="op">*</span><span class="op">/</span>
i_	<span class="ohdr">ftgen</span> 3, 0, 4096, 7, 0, 512, 0.25, 512, 1, 512, 0.25, 512,	\
			     0, 512, <span class="op">-</span>0.25, 512, <span class="op">-</span>1, 512, <span class="op">-</span>0.25, 512, 0
<span class="op">/</span><span class="op">*</span> AM waveform <span class="op">*</span><span class="op">/</span>
i_	<span class="ohdr">ftgen</span> 4, 0, 4096, 5, 1, 4096, 0.01
<span class="op">/</span><span class="op">*</span> FM to EQ <span class="op">*</span><span class="op">/</span>
i_	<span class="ohdr">ftgen</span> 5, 0, 1024, 5, 1, 512, 32, 512, 1
<span class="op">/</span><span class="op">*</span> sine wave <span class="op">*</span><span class="op">/</span>
i_	<span class="ohdr">ftgen</span> 6, 0, 1024, 10, 1
<span class="op">/</span><span class="op">*</span> room parameters <span class="op">*</span><span class="op">/</span>
i_	<span class="ohdr">ftgen</span> 7, 0, 64, <span class="op">-</span>2, 4, 50, <span class="op">-</span>1, <span class="op">-</span>1, <span class="op">-</span>1, 11,			\
			    1, 26.833, 0.05, 0.85, 10000, 0.8, 0.5, 2,	\
			    1,  1.753, 0.05, 0.85,  5000, 0.8, 0.5, 2,	\
			    1, 39.451, 0.05, 0.85,  7000, 0.8, 0.5, 2,	\
			    1, 33.503, 0.05, 0.85,  7000, 0.8, 0.5, 2,	\
			    1, 36.151, 0.05, 0.85,  7000, 0.8, 0.5, 2,	\
			    1, 29.633, 0.05, 0.85,  7000, 0.8, 0.5, 2

<span class="op">/</span><span class="op">*</span> generate bandlimited sawtooth waves <span class="op">*</span><span class="op">/</span>

i0	<span class="op">=</span>  0
<span class="olabel">loop1</span><span class="op">:</span>
imaxh	<span class="op">=</span>  <span class="ohdr">sr</span> <span class="op">/</span> (2 <span class="op">*</span> 440.0 <span class="op">*</span> <span class="opc">exp</span>(<span class="opc">log</span>(2.0) <span class="op">*</span> (i0 <span class="op">-</span> 69) <span class="op">/</span> 12))
i_	<span class="ohdr">ftgen</span> i0 <span class="op">+</span> 256, 0, 4096, <span class="op">-</span>30, 1, 1, imaxh
i0	<span class="op">=</span>  i0 <span class="op">+</span> 1
	<span class="octrl">if</span> (i0 <span class="op">&lt;</span> 127.5) <span class="octrl">igoto</span> <span class="olabel">loop1</span>

	<span class="oblock">instr</span> 1

p3	<span class="op">=</span>  p3 <span class="op">+</span> 0.4

<span class="comment">; note frequency</span>
kcps	<span class="op">=</span>  440.0 <span class="op">*</span> <span class="opc">exp</span>(<span class="opc">log</span>(2.0) <span class="op">*</span> (p4 <span class="op">-</span> 69) <span class="op">/</span> 12)
<span class="comment">; lowpass max. frequency</span>
klpmaxf	limit 64 <span class="op">*</span> kcps, 1000.0, 12000.0
<span class="comment">; FM depth in Hz</span>
kfmd1	<span class="op">=</span>  0.02 <span class="op">*</span> kcps
<span class="comment">; AM frequency</span>
kamfr	<span class="op">=</span>  kcps <span class="op">*</span> 0.02
kamfr2	<span class="op">=</span>  kcps <span class="op">*</span> 0.1
<span class="comment">; table number</span>
kfnum	<span class="op">=</span>  (256 <span class="op">+</span> 69 <span class="op">+</span> 0.5 <span class="op">+</span> 12 <span class="op">*</span> <span class="opc">log</span>(kcps <span class="op">/</span> 440.0) <span class="op">/</span> <span class="opc">log</span>(2.0))
<span class="comment">; amp. envelope</span>
aenv	<span class="opc">linseg</span> 0, 0.1, 1.0, p3 <span class="op">-</span> 0.5, 1.0, 0.1, 0.5, 0.2, 0, 1.0, 0

<span class="op">/</span><span class="op">*</span> oscillator <span class="op">/</span> left <span class="op">*</span><span class="op">/</span>

a1	<span class="opc">oscbnk</span> kcps, 0.0, kfmd1, 0.0, 40, 200, 0.1, 0.2, 0, 0, 144,	      \
		0.0, klpmaxf, 0.0, 0.0, 1.5, 1.5, 2,			      \
		kfnum, 3, 0, 5, 5, 5
a2	<span class="opc">oscbnk</span> kcps, 1.0, kfmd1, 0.0, 40, 201, 0.1, 0.2, kamfr, kamfr2, 148,  \
		0, 0, 0, 0, 0, 0, <span class="op">-</span>1,					      \
		kfnum, 3, 4
a2	<span class="opc">pareq</span> a2, kcps <span class="op">*</span> 8, 0.0, 0.7071, 2
a0	<span class="op">=</span>  a1 <span class="op">+</span> a2 <span class="op">*</span> 0.12
<span class="op">/</span><span class="op">*</span> <span class="opc">delay</span> <span class="op">*</span><span class="op">/</span>
adel	<span class="op">=</span>  0.001
a01	<span class="opc">vdelayx</span> a0, adel, 0.01, 16
a_	<span class="opc">oscili</span> 1.0, 0.25, 6, 0.0
adel	<span class="op">=</span>  adel <span class="op">+</span> 1.0 <span class="op">/</span> (<span class="opc">exp</span>(<span class="opc">log</span>(2.0) <span class="op">*</span> a_) <span class="op">*</span> 8000)
a02	<span class="opc">vdelayx</span> a0, adel, 0.01, 16
a0	<span class="op">=</span>  a01 <span class="op">+</span> a02

ga01	<span class="op">=</span>  ga01 <span class="op">+</span> a0 <span class="op">*</span> aenv <span class="op">*</span> 2500

<span class="op">/</span><span class="op">*</span> oscillator <span class="op">/</span> right <span class="op">*</span><span class="op">/</span>

<span class="comment">; lowpass max. frequency</span>

a1	<span class="opc">oscbnk</span> kcps, 0.0, kfmd1, 0.0, 40, 202, 0.1, 0.2, 0, 0, 144,	      \
		0.0, klpmaxf, 0.0, 0.0, 1.0, 1.0, 2,			      \
		kfnum, 3, 0, 5, 5, 5
a2	<span class="opc">oscbnk</span> kcps, 1.0, kfmd1, 0.0, 40, 203, 0.1, 0.2, kamfr, kamfr2, 148,  \
		0, 0, 0, 0, 0, 0, <span class="op">-</span>1,					      \
		kfnum, 3, 4
a2	<span class="opc">pareq</span> a2, kcps <span class="op">*</span> 8, 0.0, 0.7071, 2
a0	<span class="op">=</span>  a1 <span class="op">+</span> a2 <span class="op">*</span> 0.12
<span class="op">/</span><span class="op">*</span> <span class="opc">delay</span> <span class="op">*</span><span class="op">/</span>
adel	<span class="op">=</span>  0.001
a01	<span class="opc">vdelayx</span> a0, adel, 0.01, 16
a_	<span class="opc">oscili</span> 1.0, 0.25, 6, 0.25
adel	<span class="op">=</span>  adel <span class="op">+</span> 1.0 <span class="op">/</span> (<span class="opc">exp</span>(<span class="opc">log</span>(2.0) <span class="op">*</span> a_) <span class="op">*</span> 8000)
a02	<span class="opc">vdelayx</span> a0, adel, 0.01, 16
a0	<span class="op">=</span>  a01 <span class="op">+</span> a02

ga02	<span class="op">=</span>  ga02 <span class="op">+</span> a0 <span class="op">*</span> aenv <span class="op">*</span> 2500


	<span class="oblock">endin</span>

<span class="op">/</span><span class="op">*</span> output <span class="op">/</span> left <span class="op">*</span><span class="op">/</span>

	<span class="oblock">instr</span> 81

i1	<span class="op">=</span>  0.000001
aLl, aLh, aRl, aRh	<span class="opc">spat3di</span> ga01 <span class="op">+</span> i1<span class="op">*</span>i1<span class="op">*</span>i1<span class="op">*</span>i1, <span class="op">-</span>8.0, 4.0, 0.0, 0.3, 7, 4
ga01	<span class="op">=</span>  0
aLl	<span class="opc">butterlp</span> aLl, 800.0
aRl	<span class="opc">butterlp</span> aRl, 800.0

	<span class="opc">outs</span> aLl <span class="op">+</span> aLh, aRl <span class="op">+</span> aRh

	<span class="oblock">endin</span>

<span class="op">/</span><span class="op">*</span> output <span class="op">/</span> right <span class="op">*</span><span class="op">/</span>

	<span class="oblock">instr</span> 82

i1	<span class="op">=</span>  0.000001
aLl, aLh, aRl, aRh	<span class="opc">spat3di</span> ga02 <span class="op">+</span> i1<span class="op">*</span>i1<span class="op">*</span>i1<span class="op">*</span>i1, 8.0, 4.0, 0.0, 0.3, 7, 4
ga02	<span class="op">=</span>  0
aLl	<span class="opc">butterlp</span> aLl, 800.0
aRl	<span class="opc">butterlp</span> aRl, 800.0

	<span class="opc">outs</span> aLl <span class="op">+</span> aLh, aRl <span class="op">+</span> aRh

	<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

/* Written by Istvan Varga */
<span class="stamnt">t</span> 0 60

<span class="stamnt">i</span> 1 0 4 41
<span class="stamnt">i</span> 1 0 4 60
<span class="stamnt">i</span> 1 0 4 65
<span class="stamnt">i</span> 1 0 4 69

<span class="stamnt">i</span> 81 0 5.5
<span class="stamnt">i</span> 82 0 5.5
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp128989424"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Istvan Varga</td>
          </tr>
          <tr>
            <td>2001</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 4.15</p>
        <p>Updated April 2002 by Istvan Varga</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="opcode.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="oscil1.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">opcode </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> oscil1</td>
        </tr>
      </table>
    </div>
  </body>
</html>
